<?php


class Blackbird_Form_Content_Comment extends Zend_Form
{
	function __construct($options = null)
	{
		parent::__construct($options);

		$this
			->addElement('hash', 'csrf')

			->addElement('textarea', 'content', array(
				'id' => 'comment-content',
				'cols' => 65,
				'filters' => array('StripTags', 'StringTrim'),
				'label' => 'Comentario:',
				'required' => true,
				'rows' => 5,
				'style' => 'width:450px',
				'validators' => array('NotEmpty'),
			))
			;

		$auth = Zend_Auth::getInstance();
		$isInAdmin = isset($options['isInAdmin']) && true == $options['isInAdmin'];
		if (!$auth->hasIdentity() || $isInAdmin)
		{
			$this
				->addElement('text', 'authorName', array(
					'class' => 'important',
					'filters' => array('StripTags', 'StringTrim'),
					'label' => 'Nombres:',
					'maxlength' => 100,
					'required' => true,
					'validators' => array(array('StringLength', true, array('min' => 2, 'max' => 100))),
				))

				->addElement('text', 'authorEmail', array(
					'class' => 'important',
					'filters' => array('StripTags', 'StringTrim'),
					'label' => 'E-mail:',
					'maxlength' => 100,
					'required' => true,
					'validators' => array('EmailAddress', array('StringLength', true, array('min' => 1, 'max' => 200))),
				));

				if (!$isInAdmin)
				{
					$this->addElement('captcha', 'human', array(
						'label' => 'Ingrese el texto de la imágen:',
						'captcha' => array(
							'captcha' => 'image',
							'imgUrl' => BASE_URL . '/uploads/captcha',
							'imgDir' => BASE_PATH . '/uploads/captcha',
							'wordLen' => 4,
							'font' => LIBRARY_PATH . '/Blackbird/fonts/Vera.ttf',
						),
						'required' => true,
					));
				}
		}

		$this
			->addElement('button', 'submit', array(
				'label' => 'Enviar',
				'ignore' => true,
				'type' => 'submit',
			))

			->addElement('button', 'cancel', array(
				'label' => 'Cancelar',
				'ignore' => true,
				'type' => 'button',
				'onclick' => 'history.go(-1)',
			));

		$this->csrf
			->removeDecorator('DtDdWrapper')
			->removeDecorator('Label');

		$this->submit
			->removeDecorator('DtDdWrapper')
			->addDecorator('HtmlTag', array(
				'class' => 'buttons',
				'openOnly' => true,
				'tag' => 'dd',
			));

		$this->cancel
			->removeDecorator('DtDdWrapper')
			->addDecorator('HtmlTag', array(
				'closeOnly' => true,
				'tag' => 'dd',
			));
	}
}

